<%--
  Created by IntelliJ IDEA.
  User: 杨飞龙
  Date: 2020/5/31
  Time: 0:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
    <!-- 设置页面的 基本路径，页面所有资源引入和页面的跳转全部基于 base路径 -->
    <base href="<%=basePath%>">

    <link rel="stylesheet" type="text/css" href="lib/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="lib/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="lib/z-tree/css/zTreeStyle/zTreeStyle.css">


    <%--js--%>
    <script type="text/javascript" src="lib/easyui/jquery.min.js">
    </script>
    <script type="text/javascript" src="lib/easyui/jquery.easyui.min.js">
    </script>
    <script type="text/javascript" src="lib/z-tree/js/jquery.ztree.all.js"></script>
    <script type="text/javascript" src="lib/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="lib/jquery.serializejson/jquery.serializejson.min.js"></script>
</head>
<body>

<%--添加账号--%>
<div id="addCompanyWindow" class="easyui-window" title="添加账号" style="width:500px;height:500px"
     data-options="modal:true,closed:true">

    <form id="companyForm" method="post">
        <input type="hidden" name="cid">
        <div style="padding: 10px 50px">
            <input required class="easyui-textbox" prompt="请输入您的公司名称："
                   data-options="missingMessage:'公司名称不能为空',label:'公司名称：'"
                   style="width:100%;height:30px;padding:10px" name="cname" >
        </div>
        <div style="padding: 10px 50px">
            <input required class="easyui-textbox" prompt="请输入您的姓名："
                   data-options="missingMessage:'公司名称不能为空',label:'法人姓名：'"
                   style="width:100%;height:30px;padding:10px" name="ceo" >
        </div>
        <div style="padding: 10px 50px">
            <input required class="easyui-passwordbox" prompt="请输入密码" iconWidth="28"
                   style="width:100%;height:30px;padding:10px" id="cpwd"
                   data-options="showEye:false,missingMessage:'密码不能为空',label:'密码：'"
                   name="cpwd">
        </div>
        <div style="padding: 10px 50px">
            <input  class="easyui-passwordbox" prompt="请再次输入密码" iconWidth="28"
                   style="width:100%;height:30px;padding:10px"
                   data-options="showEye:false,missingMessage:'密码不能为空',label:'确认密码：'"
                   required="required" validType="equals['#cpwd']" invalidMessage="两次输入密码不匹配"
                   >
        </div>
        <div style="padding: 10px 50px">
            <input required class="easyui-textbox" prompt="请输入您的手机号" iconWidth="28"
                   style="width:100%;height:30px;padding:10px"
                   data-options="label:'手机号：'"
                   name="cphone" >
        </div>
        <div style="padding: 10px 50px">
            <input required class="easyui-textbox" prompt="请输入您的邮箱" iconWidth="28"
                   style="width:100%;height:30px;padding:10px"
                   data-options="label:'邮箱：',validType:'email' ,invalidMessage:'邮箱格式不正确'"
                   name="cmail">
        </div>


        <div style="padding: 15px 50px;text-align: center">
            <a onclick="insertCompany()" href="javascript:void(0)" class="easyui-linkbutton">提交</a>
        </div>

    </form>
</div>

<%--策划师列表--%>
<div id="plannerListWindow" class="easyui-window" style="width:80%;height:60%"
     data-options="modal:true,closed:true">
    <table id="plannerTabs" style="height:100%"></table>
</div>

<%--条件搜索框--%>
<div id="tb" style="padding:2px 5px;">
    <form id="companySearchForm" action="company/list.do">
        <input class="easyui-textbox" name="cname" prompt="公司名称（可不填）" style="width:110px">
        <select class="easyui-combobox" name="status" panelHeight="auto" style="width:100px">
            <option value="">账号状态</option>
            <option value="1">禁用</option>
            <option value="2">正常</option>
        </select>

        <select name="ordernumber" class="easyui-combobox" panelHeight="auto" style="width:110px">
            <option value="">订单量排序</option>
            <option value="desc">订单量降序</option>
            <option value="asc">订单量升序</option>
        </select>

        <a href="javascript:void(0)" onclick="searchCompany()" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
    </form>
</div>

<%--linkenbutton--%>
<div id="tt" style="padding:5px 0;">
    <a id="companyAdd"  href="javascript:void(0)" class="easyui-linkbutton"
       data-options="iconCls:'icon-add'">添加</a>
    <a id="delCompany" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
    <a id="editCompany" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">编辑</a>
    <a id="plannerList" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-tip'">策划师列表</a>
    <a id="status" href="javascript:void(0)" class="easyui-linkbutton" <%--data-options="iconCls:'icon-clear'"--%>
       iconCls="icon-clear"><span
            id="status_sp">禁用启用账号</span></a>
</div>

<table id="dataTabs" style="height:500px"></table>


<script type="text/javascript">


    $(function () {
        $('#dataTabs').datagrid({
            url: 'company/list.do',
            fit: true,
            fitColumns: true,
            pagination: true,//分页条
            checkOnSelect: false,
            striped: true,
            toolbar: '#tt',//顶部工具栏
            header: '#tb',
            columns: [[

                {field: '', checkbox: true},
                {field: 'cid', title: '编号'},
                {field: 'cname', title: '公司名称', width: 100},
                {field: 'ceo', title: '法人', width: 100, align: 'right'},
                {field: 'cphone', title: '手机号', width: 100},
                {field: 'cmail', title: '邮箱', width: 100},
                {
                    field: 'starttime', title: '开通时间', width: 100, formatter(value, row, index) {
                        return value.year + '-' + value.monthValue + '-' + value.dayOfMonth
                    }
                },
                {field: 'ordernumber', title: '订单量', width: 100},
                {
                    field: 'status', title: '账号状态', width: 100, formatter: function (value, row, index) {
                        if (value == 0) {
                            return "<span style='color: #bfbfbf'>未审核</span>"
                        }
                        if (value == 1) {
                            return "<span style='color: red'>禁用</span>"
                        }
                        if (value == 2) {
                            return "<span >正常</span>"
                        }
                    }
                }
            ]],
            onCheck:function (index,row) {
                var comStatus = row.status;

                if (comStatus == 0) {
                    $("#status_sp").text("账号审核")
                }
                if (comStatus == 1) {
                    $("#status_sp").text("账号启用")
                }
                if (comStatus == 2) {
                    $("#status_sp").text("账号禁用")
                }
            }
        });
    })
</script>

<%--策划师列表--%>
<script type="text/javascript">

    $("#plannerList").click(function () {
        var flag = $("#dataTabs").datagrid('getChecked');


        if (flag.length == 0 ) {
            $.messager.alert("策划师列表", "至少选择一家公司", "info")
            return false
        }else  if (flag.length > 1){
            $.messager.alert("策划师列表", "一次只能查看一家公司", "info")
            $("#dataTabs").datagrid('clearChecked');
            return false
        }
        $("#plannerListWindow").window({
            title:flag[0].cname+"策划师列表",
            closed:false,
            onClose:function (index,row) {
                $("#dataTabs").datagrid('clearChecked');
            }
        })
        var comCid=flag[0].cid

        $('#plannerTabs').datagrid({
            url: 'planner/list.do?cid='+comCid,
            fit: true,
            fitColumns: true,
            striped: true,
            columns: [[
                {field: 'nid', title: '编号'},
                {field: 'nname', title: '姓名', width: 100},
                {field: 'nphone', title: '手机号', width: 100},
                {field: 'addtime', title: '添加时间', width: 100},
                {field: 'ordernumber', title: '订单量', width: 100},
                {
                    field: 'status', title: '账号状态', width: 100, formatter: function (value, row, index) {
                        if (value == 0) {
                            return "<span style='color: red'>禁用</span>"
                        }
                        if (value == 1) {
                            return "<span>正常</span>"
                        }

                    }
                }
            ]],
            onLoadSuccess:function () {
               var row=$("#plannerTabs").datagrid('getData')
                if (row.rows.length == 0){
                    $.messager.alert("策划师列表","您选择的此公司暂时没有策划师哦","info",function () {
                        $("#plannerListWindow").window('close');
                    })

                }
            }
        });
    })

</script>

<script type="text/javascript">
    //条件搜索
    function searchCompany() {
        var formData = $("#companySearchForm").serializeJSON();

        $("#dataTabs").datagrid('load', formData);
    }

    //动态改变



    /*账号状态设置--start*/
    $("#status").click(function () {
        var flag = $("#dataTabs").datagrid('getChecked');
        if (flag.length == 0 ) {
            $.messager.alert("账号状态修改", "至少选择一条数据", "info")
            return false
        }else  if (flag.length > 1){
            $.messager.alert("账号状态修改", "一次只能操作一条数据", "info")
            $("#dataTabs").datagrid('clearChecked');
            return false
        }

        var company = flag[0]

        if (company.status == 0) {
            $.messager.confirm('禁用启用账号', '您是否确定审核通过该账号,该状态时候不可登录，不可下单', function (r) {
                if (r) {
                    comfimStatus()
                }
            })
        }
        if (company.status == 1) {
            $.messager.confirm('禁用启用账号', '您是否确定恢复该账号,该状态时候不可登录，不可下单', function (r) {
                if (r) {
                    comfimStatus()
                }
            })
        }
        if (company.status == 2) {
            $.messager.confirm('禁用启用账号', '您是否确定禁用该账号', function (r) {
                if (r) {
                    comfimStatus()
                }
            })
        }


    })

    function comfimStatus() {
        var flag = $("#dataTabs").datagrid('getChecked');
        var company = flag[0]
        $.post("company/changeStatus.do?", {status: company.status, cid: company.cid}, function (data) {
            if (data) {
                //刷新页面
                $("#dataTabs").datagrid('reload');
                $.messager.alert('禁用启用账号', '修改账号状态成功', 'info')
            } else {
                //刷新页面
                $("#dataTabs").datagrid('reload');
                $.messager.alert('禁用启用账号', '修改账号状态失败', 'info')
            }
        })
    }

    /*账号状态设置--end*/

    /*添加账号 --start*/
    $("#companyAdd").click(function () {
        $("#addCompanyWindow").window({
            closed: false
        })
    })

    function insertCompany() {
        $("#companyForm").form('submit', {
            url:'company/saveOrUpdate.do',
            onSubmit: function () {
                var flag = $('#companyForm').form('validate');
                return flag;
            },
            success: function (data) {
                if (data) {
                    $('#addCompanyWindow').window({
                        closed: true
                    });
                    //清除表单
                    $("#companyForm").form('reset');
                    //刷新页面
                    $("#dataTabs").datagrid('reload');
                    $.messager.alert('温馨提示', '操作账号成功', 'info')
                } else {
                    $('#addCompanyWindow').window({
                        closed: true
                    });
                    //清除表单
                    $("#companyForm").form('reset');
                    //刷新页面
                    $("#dataTabs").datagrid('reload');
                    $.messager.alert('温馨提示', '操作账号失败', 'info')
                }
            }
        });
    }
    /*添加账号 --end*/

    /*编辑账号 --start*/
    $("#editCompany").click(function () {
        var check= $("#dataTabs").datagrid('getChecked');

        if (check.length == 0) {
            $.messager.alert("编辑账号","至少选择一条数据","info")
            return false
        }else if( check.length > 1){
            $.messager.alert("编辑账号","一次只能操作一条数据","info")
            $("#dataTabs").datagrid('clearChecked');
            return false

        }

        var company=check[0]


        $("#addCompanyWindow").window({
            closed:false
        })

        company.cpwd=null
        //回显数据
        $('#companyForm').form('load',company);


    })

    /*编辑账号 --end*/

    /*删除账号 -- start*/
    $("#delCompany").click(function () {
        //获取选择的id
        var check = $("#dataTabs").datagrid("getChecked");

        if (check.length == 0) {
            $.messager.alert("删除账号", "至少选择一条数据", "info")
            return false
        }

        var cids = []

        $.each(check, function (index, company) {
            cids.push(company.cid)
        })

        $.messager.confirm('删除账号', '你确定要删除选中的账号吗?', function(r){
            if (r){
                $.get("company/deleteCompnay.do?cids=" + cids, function (data) {
                    if (data){
                        $("#dataTabs").datagrid('reload');
                        $.messager.alert('删除账号', '删除成功', 'info')
                    }else {
                        $("#dataTabs").datagrid('reload');
                        $.messager.alert('删除账号', '删除失败', 'info')
                    }
                })
            }
        });

    })
    /*删除账号 -- end*/

</script>
</body>
</html>
